import FingerprintJS from '@fingerprintjs/fingerprintjs'
import { v4 as uuidv4 } from 'uuid';


const fpPromise = FingerprintJS.load()

export async function getFingerprintId() {
  const fingerprintIdTemp = localStorage.getItem('__DC_STAT_UUID')
  if (fingerprintIdTemp) return fingerprintIdTemp;
  const fp = await fpPromise
  const result = await fp.get()
  const id = result.visitorId ? result.visitorId : uuidv4();
  localStorage.setItem('__DC_STAT_UUID', id)
  return id;
}
